class Gun:
    def __init__(self,model):
        self.model = model
        self.bullet_count = 0

    def add_bullet(self,count):
        self.bullet_count += count

    def shoot(self):
        if self.bullet_count <= 0:
            print("没有子弹了")
            return
        
        self.bullet_count -= 1
        print("[%s]剩余子弹：%d" %(self.model,self.bullet_count))



class Soldier:
    def __init__(self,name):
        self.name = name
        # 新兵没有枪，不能给枪创建属性,所以赋予一个空属性
        self.gun = None

    def fire(self,count):
        if self.gun is None:  # if self.gun == None:
            print("士兵[%s]没有枪")
            return
        
        self.gun.add_bullet(count)
        self.gun.shoot()

AK47 = Gun("AK47")
# AK47.add_bullet(50)
# AK47.shoot()

SSD = Soldier("许三多")
SSD.gun = AK47
bullet_count = int(input("添加子弹："))

SSD.fire(bullet_count)

print(SSD.gun)
